<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <title>Document</title>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form" style="margin-top:10px">
        <input type="hidden" name="userId" th:value="${user.userId}" id="userId">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名：</label>
            <div class="layui-input-block">
                <input type="text" name="userName" th:value="${user.userName}" lay-verify="required" placeholder="请修改用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系邮箱：</label>
            <div class="layui-input-block">
                <input type="text" name="email" th:value="${user.email}" lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码：</label>
            <div class="layui-input-block">
                <input type="text" name="userPassword" th:value="${user.userPassword}" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="lay-form-submit" id="lay-form-submit">
        </div>

    </div>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
    layui.use(['form'], function() {
        var form = layui.form;
        var $ = layui.$;



        //监听提交
        form.on('submit(lay-form-submit)', function(data) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交ajax成功后，关闭当前弹层并重载表格
            $.ajax({
                type: 'post',
                url: '/user/save',
                data: data.field,
                success: function(json) {
                    parent.layer.close(index); //再执行关闭
                    window.parent.location.reload();
                }
            });
        });

    });

</script>

</body>
</html>